package com.meituan.verintreport.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.TimeZone;

/**
 * @Description: java类作用描述
 * @Author: huzhantao
 * @CreateDate: 2019/3/21 18:28
 **/
@Slf4j
@Component
public class DateUtil {

    /**
     *
     * @param day 多少天之前
     * @return
     */
    public static String getDate(int day,String reportTimeZone){

        LocalDate localDate = LocalDate.now();
        String date = localDate.toString() + " 00:00:00";

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = 0L;
        try {
            time = df.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        TimeZone timezone;
        if (null == reportTimeZone){
            timezone = TimeZone.getTimeZone("GMT");
        }else {
            timezone = TimeZone.getTimeZone(reportTimeZone);
        }
        df.setTimeZone(timezone);

        long time2 = (long) day * 24 * 60 * 60 * 1000;
        String date2 = df.format(time - time2);
        return date2;

    }

}
